package cn.fintecher.pangolin.service.business.service;

import cn.fintecher.pangolin.common.enums.*;
import cn.fintecher.pangolin.common.exception.BadRequestException;
import cn.fintecher.pangolin.common.model.UserModel;
import cn.fintecher.pangolin.common.utils.BeanUtils;
import cn.fintecher.pangolin.common.utils.ZWDateUtil;
import cn.fintecher.pangolin.entity.elastic.*;
import cn.fintecher.pangolin.entity.mysql.CaseInfo;
import cn.fintecher.pangolin.entity.mysql.PaymentCheck;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.entity.mysql.QPaymentCheck;
import cn.fintecher.pangolin.service.business.model.request.*;
import cn.fintecher.pangolin.service.business.model.response.CheckStringResponse;
import cn.fintecher.pangolin.service.business.model.response.FindCaseFollowRecordResponse;
import cn.fintecher.pangolin.service.business.repository.elasticsearch.*;
import cn.fintecher.pangolin.service.business.repository.jparepository.CaseInfoRepository;
import cn.fintecher.pangolin.service.business.repository.jparepository.PaymentCheckRepository;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Type;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Auther: xiaqun
 * @Description:
 * @Date: 18:18 2019/9/16
 */

@Service("caseFollowRecordService")
@Transactional(rollbackFor = Exception.class)
public class CaseFollowRecordService {
    @Autowired
    private BaseService baseService;

    @Autowired
    private ModelMapper modelMapper;

    @Autowired
    private CaseFollowRecordElastic caseFollowRecordElastic;

    @Autowired
    private FindRecordElastic findRecordElastic;

    @Autowired
    private OtherRecordElastic otherRecordElastic;

    @Autowired
    private CommentRespository commentRespository;

    @Autowired
    private CaseInfoRepository caseInfoRepository;

    @Autowired
    private SensitiveWordElastic sensitiveWordElastic;

    @Autowired
    private PreRecordElastic preRecordElastic;

    @Autowired
    private HistoryCasesRespository historyCasesRespository;

    @Autowired
    private BaseCaseRespository baseCaseRespository;

    @Autowired
    private PersonalContactElastic personalContactElastic;

    @Autowired
    private PaymentCheckRepository paymentCheckRepository;

    /**
     * 催记查询
     */
    public Page<FindCaseFollowRecordResponse> getAllCaseFollowRecord(FindCaseFollowRecordRequest request, Pageable pageable, String token) {
        UserModel userModel = baseService.getUserByToken(token);
        BoolQueryBuilder builder = request.getBuilder();
        baseService.spliceBuilder(builder, userModel);
        SearchQuery searchQuery = generateQuery(builder, pageable);
        Page<CaseFollowupRecord> page = caseFollowRecordElastic.search(searchQuery);
        return page.map(e -> modelMapper.map(e, FindCaseFollowRecordResponse.class));
    }

    /**
     * 删除催记
     */
    public void deleteCaseFollowRecord(String id, CaseType caseType) {
        CaseFollowupRecord caseFollowupRecord = caseFollowRecordElastic.findById(id).orElseThrow(() -> new BadRequestException(null, "caseFollowRecord", "caseFollowRecord.is.null"));
        Optional<CaseInfo> optional = caseInfoRepository.findById(caseFollowupRecord.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, caseType);
        if (caseFollowupRecord.getType().equals(FollowType.TEL)) {
            caseInfo.setTelRecordCount(caseInfo.getTelRecordCount() - 1);
        } else if (caseFollowupRecord.getType().equals(FollowType.ADDR)) {
            caseInfo.setAddrRecordCount(caseInfo.getAddrRecordCount() - 1);
        }
        caseInfo.setCollectionRecordCount(caseInfo.getCollectionRecordCount() - 1);
        caseInfo.setCollectionTotalRecordCount(caseInfo.getCollectionTotalRecordCount() - 1);
        caseInfoRepository.save(caseInfo);
        caseFollowRecordElastic.deleteById(id);
    }

    /**
     * @Author wangxiangdong
     * @Description 修改催记
     * @Date 2019/10/18 17:38
     **/
    public void updateCaseFollowRecord(UpdateFollowUpRecordRequest updateFollowUpRecordRequest) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(updateFollowUpRecordRequest.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, updateFollowUpRecordRequest.getCaseType());
        CaseFollowupRecord updateCaseFollowRecord = caseFollowRecordElastic.findById(updateFollowUpRecordRequest.getId()).orElseThrow(() -> new BadRequestException(null, "updateCaseFollowRecord", "record.is.exist"));
        updateCaseFollowRecord.setContent(updateFollowUpRecordRequest.getContent());
        updateCaseFollowRecord.setOperateTime(updateFollowUpRecordRequest.getOperateTime());
        caseFollowRecordElastic.save(updateCaseFollowRecord);
    }

    /**
     * 添加催记
     */
    public CaseFollowupRecord addCaseFollowRecord(AddCaseFollowRecordRequest request, String token) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(request.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, request.getCaseType());
        UserModel userModel = baseService.getUserByToken(token);
        CaseFollowupRecord caseFollowupRecord = new CaseFollowupRecord();
        BeanUtils.copyPropertiesIgnoreNull(request, caseFollowupRecord);
        caseFollowupRecord.setCertificate(request.getCertificate());
        caseFollowupRecord.setRecord(request.getRecord());
        caseFollowupRecord.setVideo(request.getVideo());
        caseFollowupRecord.process(userModel.getId(), userModel.getRealName(), ZWDateUtil.getNowDateTime());
        caseFollowupRecord.setCaseId(request.getCaseId());
        caseFollowupRecord.setOutCollector(request.getOutCollector());
        if (StringUtils.isNotBlank(request.getFilename()) && StringUtils.isNotBlank(request.getFilepath())) {
            caseFollowupRecord.setUrl(request.getFilepath().concat(request.getFilename()));
        }
        //统计催记数
        if (request.getType().equals(FollowType.TEL) && StringUtils.isNotBlank(request.getContactPhone())) { //电催
            caseInfo.setTelRecordCount(Objects.isNull(caseInfo.getTelRecordCount()) ? 1 : caseInfo.getTelRecordCount() + 1);
            //修改相同电话的联系人的联络结果
            BoolQueryBuilder builder = new BoolQueryBuilder();
            builder.must(QueryBuilders.matchPhraseQuery("phoneNo.keyword", request.getContactPhone()));
            Iterable<PersonalContact> iterable = personalContactElastic.search(builder);
            if (iterable.iterator().hasNext()) {
                iterable.forEach(e -> e.setContactResult(request.getContactResult()));
                personalContactElastic.saveAll(iterable);
            }
        } else if (request.getType().equals(FollowType.ADDR)) { //外访
            caseInfo.setAddrRecordCount(Objects.isNull(caseInfo.getAddrRecordCount()) ? 1 : caseInfo.getAddrRecordCount() + 1);
        }
        payCheck(request, userModel, caseInfo);
        caseInfo.setCollectionRecordCount(Objects.isNull(caseInfo.getCollectionRecordCount()) ? 1 : caseInfo.getCollectionRecordCount() + 1);
        caseInfo.setCollectionTotalRecordCount(Objects.isNull(caseInfo.getCollectionTotalRecordCount()) ? 1 : caseInfo.getCollectionTotalRecordCount() + 1);
        caseInfo.setFollowTime(ZWDateUtil.getNowDateTime());
        caseInfo.setPromiseDate(request.getPromiseDate());
        caseInfo.setLastContactResult(request.getContactResult());
        caseInfo.setLastContactDate(ZWDateUtil.getNowDateTime());
        caseInfoRepository.save(caseInfo);
        caseFollowupRecord.setPrincipalId(caseInfo.getPrincipalId());
        caseFollowupRecord.setPayAmount(request.getPayAmount());
        caseFollowupRecord.setPayDate(request.getPayDate());
        caseFollowupRecord.setPrincipalName(caseInfo.getPrincipalName());
        caseFollowupRecord.setPersonalName(caseInfo.getPersonalName());
        caseFollowupRecord.setCertificateNo(caseInfo.getCertificateNo());
        caseFollowupRecord.setCaseNumber(caseInfo.getCaseNumber());
        caseFollowupRecord.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        //caseFollowupRecord.setRecord( getFile(request.getFilepath(),request.getFilename()));
        CaseFollowupRecord newCaseFollowRecord = caseFollowRecordElastic.save(caseFollowupRecord);
        return newCaseFollowRecord;
    }

    /**
     * @Author wangxiangdong
     * @Description 检测是否需要添加ptp cp  记录。
     * @Date 2019/11/20 9:39
     **/
    private void payCheck(AddCaseFollowRecordRequest request, UserModel userModel, CaseInfo caseInfo) {
        PaymentCheck paymentCheck;
        if (Objects.nonNull(request.getPromiseAmt()) && Objects.isNull(request.getPayAmount())) {
//            Optional<PaymentCheck> paymentCheckOptional = paymentCheckRepository.findOne(QPaymentCheck.paymentCheck.caseId.eq(request.getCaseId())
//                    .and(QPaymentCheck.paymentCheck.isBouncedCheck.eq(BaseSelect.NO)).
//                            and(QPaymentCheck.paymentCheck.payCheckStatus.eq(PayCheckStatus.PTP)));
//            paymentCheck = paymentCheckOptional.orElseGet(PaymentCheck::new);
            paymentCheck = new PaymentCheck();
            paymentCheck.setCaseId(caseInfo.getId());
            paymentCheck.setCertificateNo(caseInfo.getCertificateNo());
            paymentCheck.setPersonalName(caseInfo.getPersonalName());
            paymentCheck.setOperator(userModel.getId());
            paymentCheck.setBatchNumber(caseInfo.getBatchNumber());
            paymentCheck.setCaseNumber(caseInfo.getCaseNumber());
            paymentCheck.setPrincipalId(caseInfo.getPrincipalId());
            paymentCheck.setPrincipalName(caseInfo.getPrincipalName());
            paymentCheck.setIsBouncedCheck(BaseSelect.NO);
            paymentCheck.setOperatorDate(ZWDateUtil.getNowDateTime());
            paymentCheck.setApplyName(userModel.getRealName());
            paymentCheck.setApplyDate(ZWDateUtil.getNowDateTime());
            paymentCheck.setIsReply(BaseSelect.NO);
            paymentCheck.setExportState(ExportState.WAIT_EXPORT);
            paymentCheck.setPromiseAmt(request.getPromiseAmt());
            paymentCheck.setPromiseDate(request.getPromiseDate());
            paymentCheck.setPayCheckStatus(PayCheckStatus.PTP);
            paymentCheckRepository.save(paymentCheck);
        }
        if (Objects.nonNull(request.getPayAmount())) {
//            long count = paymentCheckRepository.count(QPaymentCheck.paymentCheck.caseId.eq(request.getCaseId())
//                    .and(QPaymentCheck.paymentCheck.isReply.eq(BaseSelect.NO)).
//                            and(QPaymentCheck.paymentCheck.payCheckStatus.eq(PayCheckStatus.CP)));
//            if (count == 0) {
            PaymentCheck cpCheck = new PaymentCheck();
            cpCheck.setCaseId(caseInfo.getId());
            cpCheck.setCertificateNo(caseInfo.getCertificateNo());
            cpCheck.setPersonalName(caseInfo.getPersonalName());
            cpCheck.setOperator(userModel.getId());
            cpCheck.setBatchNumber(caseInfo.getBatchNumber());
            cpCheck.setCaseNumber(caseInfo.getCaseNumber());
            cpCheck.setPrincipalId(caseInfo.getPrincipalId());
            cpCheck.setPrincipalName(caseInfo.getPrincipalName());
            cpCheck.setIsBouncedCheck(BaseSelect.NO);
            cpCheck.setOperatorDate(ZWDateUtil.getNowDateTime());
            cpCheck.setApplyName(userModel.getRealName());
            cpCheck.setApplyDate(ZWDateUtil.getNowDateTime());
            cpCheck.setIsReply(BaseSelect.NO);
            cpCheck.setApplyId(userModel.getId());
            cpCheck.setExportState(ExportState.WAIT_EXPORT);
            cpCheck.setPromiseAmt(request.getPromiseAmt());
            cpCheck.setPromiseDate(request.getPromiseDate());
            cpCheck.setHasPaymentAmt(request.getPayAmount());
            cpCheck.setHasPaymentDate(request.getPayDate());
            cpCheck.setPayCheckStatus(PayCheckStatus.CP);
            paymentCheckRepository.save(cpCheck);
//            }
        }
    }

    /**
     * 查找记录查询
     */
    public Page<FindRecord> getAllFindRecord(FindRecordRequest request, Pageable pageable) {
        BoolQueryBuilder builder = request.getBuilder();
        SearchQuery searchQuery = generateQuery(builder, pageable);
        return findRecordElastic.search(searchQuery);
    }

    /**
     * 添加查找记录
     */
    public void addFindRecord(AddFindRecordRequest request, String token) {
        CaseInfo caseInfo = caseInfoRepository.findOne(QCaseInfo.caseInfo.id.eq(request.getCaseId())).orElseThrow(() -> new BadRequestException(null, "caseInfo", "case.is.null"));
        checkCase(caseInfo, request.getCaseType());
        UserModel userModel = baseService.getUserByToken(token);
        FindRecord record = new FindRecord();
        BeanUtils.copyPropertiesIgnoreNull(request, record);
        record.process(userModel.getId(), userModel.getRealName(), ZWDateUtil.getNowDateTime());
        findRecordElastic.save(record);
        //统计催记数
        caseInfo.setFindRecordCount(Objects.isNull(caseInfo.getFindRecordCount()) ? 1 : caseInfo.getFindRecordCount() + 1);
        caseInfo.setCollectionRecordCount(Objects.isNull(caseInfo.getCollectionRecordCount()) ? 1 : caseInfo.getCollectionRecordCount() + 1);
        caseInfo.setCollectionTotalRecordCount(Objects.isNull(caseInfo.getCollectionTotalRecordCount()) ? 1 : caseInfo.getCollectionTotalRecordCount() + 1);
        record.setCertificateNo(caseInfo.getCertificateNo());
        caseInfoRepository.save(caseInfo);
    }

    /**
     * 其他催记查询
     */
    public Page<OtherRecord> getAllOtherRecord(FindOtherRecordRequest request, Pageable pageable) {
        BoolQueryBuilder builder = request.getBuilder();
        SearchQuery searchQuery = generateQuery(builder, pageable);
        return otherRecordElastic.search(searchQuery);
    }

    /**
     * 添加其他催记
     */
    public void addOtherRecord(AddOtherRecordRequest request, String token) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(request.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, request.getCaseType());
        UserModel userModel = baseService.getUserByToken(token);
        OtherRecord record = new OtherRecord();
        BeanUtils.copyPropertiesIgnoreNull(request, record);
        record.process(userModel.getId(), userModel.getRealName(), ZWDateUtil.getNowDateTime());
        record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        record.setCaseNumber(caseInfo.getCaseNumber());
        record.setCertificateNo(caseInfo.getCertificateNo());
        otherRecordElastic.save(record);
    }

    /**
     * 添加标注
     */
    public void addTag(AddTagRequest request, String token) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(request.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        if (!request.getCommentType().equals(CommentType.REPORT_POSTIL)) {
            checkCase(caseInfo, request.getCaseType());
        }
        UserModel userModel = baseService.getUserByToken(token);
        Comment caseTag = new Comment();
        BeanUtils.copyPropertiesIgnoreNull(request, caseTag);
        caseTag.process(userModel.getId(), userModel.getRealName(), ZWDateUtil.getNowDateTime());
        commentRespository.save(caseTag);
    }

    /**
     * 生成查询query
     */
    private SearchQuery generateQuery(BoolQueryBuilder builder, Pageable pageable) {
        SortBuilder sortBuilder = SortBuilders.fieldSort("operateTime").unmappedType("date").order(SortOrder.DESC);
        return new NativeSearchQueryBuilder().withQuery(builder).withSort(sortBuilder).withPageable(pageable).build();
    }

    /**
     * 删除标注
     */
    public void deleteTag(String id, String caseId, CaseType caseType) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(caseId);
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, caseType);
        commentRespository.deleteById(id);
    }

    /**
     * 查询标注
     */
    public Page<Comment> getAllTag(FindTagRequest request, Pageable pageable) {
        BoolQueryBuilder builder = request.getBuilder();
        SearchQuery searchQuery = generateQuery(builder, pageable);
        return commentRespository.search(searchQuery);
    }

    /**
     * 敏感词校验
     */
    public CheckStringResponse checkString(CheckStringRequest request) {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        builder.must(QueryBuilders.matchPhraseQuery("principalId.keyword", request.getPrincipalId()));
        Iterable<SensitiveWord> iterable = sensitiveWordElastic.search(builder);
        CheckStringResponse response = new CheckStringResponse();
        if (iterable.iterator().hasNext()) {
            SensitiveWord sensitiveWord = iterable.iterator().next();
            List<String> promptWords = sensitiveWord.getPromptWords();
            List<String> seriousWords = sensitiveWord.getSeriousWords();
            if ((Objects.isNull(promptWords) || promptWords.isEmpty()) && (Objects.isNull(seriousWords) || seriousWords.isEmpty())) {
                return response;
            } else {
                if (!promptWords.isEmpty()) {
                    List<String> list = new ArrayList<>();
                    promptWords.forEach(e -> {
                        if (request.getStr().toLowerCase().contains(e.toLowerCase())) {
                            list.add(request.getStr().substring(request.getStr().toLowerCase().indexOf(e.toLowerCase()), request.getStr().toLowerCase().indexOf(e.toLowerCase()) + e.length()));
                        }
                    });
                    response.setPrompt(list);
                }
                if (!seriousWords.isEmpty()) {
                    List<String> list = new ArrayList<>();
                    seriousWords.forEach(e -> {
                        if (request.getStr().toLowerCase().contains(e.toLowerCase())) {
                            list.add(request.getStr().substring(request.getStr().toLowerCase().indexOf(e.toLowerCase()), request.getStr().toLowerCase().indexOf(e.toLowerCase()) + e.length()));
                        }
                    });
                    response.setSerious(list);
                }
                return response;
            }
        } else {
            return response;
        }
    }

    /**
     * 查询委前催记
     */
    public Page<PreRecord> getAllPreRecord(FindPreRecordRequest request, Pageable pageable) {
        BoolQueryBuilder builder = request.getBuilder();
        SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).withPageable(pageable).build();
        return preRecordElastic.search(searchQuery);
    }

    /**
     * @Author wangxiangdong
     * @Description 共债跟进记录查询
     * @Date 2019/10/28 15:26
     **/
    public List<FindCaseFollowRecordResponse> getDebtFollowRecord(DebtMessageRequest debtMessageRequest, String token) {
        UserModel userModel = baseService.getUserByToken(token);
        List<String> ids;
        BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
        baseService.spliceBuilder(queryBuilder, userModel);
        queryBuilder.must(QueryBuilders.termsQuery("certificateNo.keyword", debtMessageRequest.getCertificateNo()));
        if (StringUtils.isNotBlank(debtMessageRequest.getBatchNumber())) {
            queryBuilder.must(QueryBuilders.termsQuery("batchNumber.keyword", debtMessageRequest.getBatchNumber()));
        }
        if (Objects.equals(CasePool.INPOOLCASE, debtMessageRequest.getType())) {
            List<BaseCase> baseCaseList = Lists.newArrayList(baseCaseRespository.search(queryBuilder));
            ids = baseCaseList.stream().map(BaseCase::getId).collect(Collectors.toList());
        } else {
            List<HistoryCases> historyCasesList = Lists.newArrayList(historyCasesRespository.search(queryBuilder));
            ids = historyCasesList.stream().map(HistoryCases::getId).collect(Collectors.toList());
        }
        ids.removeIf(x->Objects.equals(x,debtMessageRequest.getCaseId()));
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        boolQueryBuilder.must(QueryBuilders.termsQuery("caseId.keyword", ids));
        List<CaseFollowupRecord> caseFollowupRecords = Lists.newArrayList(caseFollowRecordElastic.search(boolQueryBuilder));
        Type typeToken = new TypeToken<List<FindCaseFollowRecordResponse>>() {
        }.getType();
        return modelMapper.map(caseFollowupRecords, typeToken);
    }

    public void replyOtherRecord(ReplyRequest replyRequest, String token) {
        Optional<CaseInfo> optional = caseInfoRepository.findById(replyRequest.getCaseId());
        if (!optional.isPresent()) {
            throw new BadRequestException(null, "caseInfo", "case.is.done");
        }
        CaseInfo caseInfo = optional.get();
        checkCase(caseInfo, replyRequest.getCaseType());
        UserModel userModel = baseService.getUserByToken(token);
        OtherRecord replyOtherRecord = otherRecordElastic.findById(replyRequest.getId()).orElseThrow(() -> new BadRequestException(null, "replyOtherRecord", "data.is.not.exists"));
        replyOtherRecord.setReplayContent(replyRequest.getReplayContent());
        replyOtherRecord.setReplayTime(ZWDateUtil.getNowDateTime());
        replyOtherRecord.setReplyName(userModel.getRealName());
        replyOtherRecord.setIsOperate(BaseSelect.YES);
        replyOtherRecord.setOperatorId(userModel.getId());
        replyOtherRecord.setOperatorName(userModel.getRealName());
        replyOtherRecord.setOperateTime(ZWDateUtil.getNowDateTime());
        otherRecordElastic.save(replyOtherRecord);
    }

    /**
     * 判断催收类型是否改变
     */
    private void checkCase(CaseInfo caseInfo, CaseType caseType) {
        if (!caseType.equals(caseInfo.getCaseType())) {
            throw new BadRequestException(null, "caseInfo", "case.type.is.change");
        }
        if (caseInfo.getCaseDataStatus().equals(CaseDataStatus.PAUSE)) {
            throw new BadRequestException(null, "caseInfo", "case.is.stop");
        }
        if (caseInfo.getCaseDataStatus().equals(CaseDataStatus.SETTLT) || caseInfo.getCaseDataStatus().equals(CaseDataStatus.REDUCE)) {
            throw new BadRequestException(null, "caseInfo", "case.is.clear");
        }
        if (caseInfo.getPublicCaseFlag().equals(PublicCaseFlag.PUBLIC_CASE)) {
            throw new BadRequestException(null, "caseInfo", "case.is.public");
        }
    }

}
